package com.naiterui.ehp.bs.emr.vo.health;

import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.emr.exception.ExceptionCodes;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @Description 过敏史
 * @Author gongbaoqiang
 * @Date 2020/6/2 2:33 PM
 */
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("过敏史")
public class AllergyVO implements Serializable {
    private static final long serialVersionUID = 37244717996948681L;

    /**
     * 外伤史
     */
    @ApiModelProperty("选项值")
    private String value;

    /**
     * 过敏史详情
     */
    @ApiModelProperty("过敏史详情")
    private AllergyDetailVO detail;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class AllergyDetailVO implements Serializable{

        private static final long serialVersionUID = 718757159329902167L;
        /**
         * 过敏源
         */
        @ApiModelProperty("过敏源")
        private String  allergen;

        /**
         * 过敏反应
         */
        @ApiModelProperty("过敏反应")
        private String anaphylaxis;

        public void validate() throws BusinessException {
            if(StringUtils.isBlank(allergen) || StringUtils.isBlank(anaphylaxis)){
                throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_ALLERY);
            }
        }
    }

    public void validate() throws BusinessException{
        if(StringUtils.isBlank(value)){
            throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_ALLERY);
        }
        if("有".equals(value)){
            detail.validate();
        }

    }
}
